<!DOCTYPE html>
<head>
    <meta charset="utf-8">
    <title>试卷试题列表页面</title>
</head>
<body class="laytp-container">
<div id="search-form" style="display:none;">
    <div class="layui-layer-title">搜索</div>
    <form class="layui-form search-form-body" lay-filter="layui-form" style="margin-top:20px;">
        <div class="layui-form-item layui-inline">
                    <label class="layui-form-label" title="ID">ID</label>
                    <div class="layui-input-inline">
                        <input autocomplete="off" type="text" id="id" name="search_param[id][value]" placeholder="请输入ID" class="layui-input">
                        <input type="hidden" name="search_param[id][condition]" value="=">
                    </div>
                </div>

        <div class="layui-form-item layui-inline">
                <label class="layui-form-label" title="试卷名称">试卷名称</label>
                <div class="layui-input-inline">
                    <input autocomplete="off" type="text" id="name" name="search_param[name][value]" placeholder="请输入试卷名称" class="layui-input">
                    <input type="hidden" name="search_param[name][condition]" value="LIKE">
                </div>
            </div>

			<div class="layui-form-item layui-inline">
                <label class="layui-form-label" title="分类">分类</label>
                <div class="layui-input-inline">
                    <div class="xmSelect"
                        data-name="search_param[category_id][value]"
                        data-sourceType="route"
                        data-source='/admin.category/index'
                        data-sourceTree="false"
                        data-paging="true"
                        data-valueField="id"
						data-textField="name"
						data-placeholder="请选择分类"
						data-direction="down"
                    ></div>
                    <input type="hidden" name="search_param[category_id][condition]" value="FIND_IN_SET">
                </div>
            </div>

			<div class="layui-form-item layui-inline">
                <label class="layui-form-label" title="课程">课程</label>
                <div class="layui-input-inline">
                    <div class="xmSelect"
                        data-name="search_param[course_id][value]"
                        data-sourceType="route"
                        data-source='/admin.course/index'
                        data-sourceTree="false"
                        data-paging="true"
                        data-valueField="id"
						data-textField="name"
						data-placeholder="请选择课程"
						data-direction="down"
                    ></div>
                    <input type="hidden" name="search_param[course_id][condition]" value="FIND_IN_SET">
                </div>
            </div>

			<div class="layui-form-item layui-inline">
                <label class="layui-form-label" title="创建人">创建人</label>
                <div class="layui-input-inline">
                    <div class="xmSelect"
                        data-name="search_param[user_id][value]"
                        data-sourceType="route"
                        data-source="/admin.user/index"
                        data-sourceTree="false"
                        data-paging="true"
                        data-valueField="id"
                        data-textField="nickname"
                        data-placeholder="请选择创建人"
                    ></div>
                    <input type="hidden" name="search_param[user_id][condition]" value="FIND_IN_SET">
                </div>
            </div>

			<div class="layui-form-item layui-inline">
                <label class="layui-form-label" title="状态">状态</label>
                <div class="layui-input-inline">
                    <select id="status" name="search_param[status][value]">
                        <option value="">请选择状态</option>
                        <option value="0">待审核</option>
						<option value="1">发布</option>
                    </select>
                    <input type="hidden" name="search_param[status][condition]" value="=">
                </div>
            </div>

        <div class="bottom">
            <div class="button-container">
                <button class="laytp-btn laytp-btn-primary laytp-btn-sm" lay-submit="" lay-filter="laytp-search-form">
                    <i class="layui-icon layui-icon-ok"></i>
                    提交
                </button>
                <button type="button" class="laytp-btn laytp-btn-sm laytp-search-form-reset">
                    <i class="layui-icon layui-icon-refresh"></i>
                    重置
                </button>
            </div>
        </div>
    </form>
</div>
<div class="layui-card">
    <div class="layui-card-body">
        <table id="laytp-table" lay-filter="laytp-table"></table>
    </div>
</div>



<script type="text/html" id="default-bar">

    {{# if(facade.hasAuth("/admin.exam.papers/delQuestion")){ }}
    <button class="laytp-btn laytp-btn-danger laytp-btn-xs" lay-event="del"><i class="layui-icon layui-icon-delete"></i>删除</button>
    {{# } }}


</script>

<script>
    if(localStorage.getItem("staticDomain")){
        document.write("<link rel='stylesheet' href='" + localStorage.getItem("staticDomain") + "/component/laytp/css/laytp.css?v=" + Date.now() + "'>");
        document.write("<script src='" + localStorage.getItem("staticDomain") + "/component/layui/layui.js?v=" + Date.now() + "'><\/script>");
        document.write("<script src='" + localStorage.getItem("staticDomain") + "/component/laytp/layuiConfig.js?v=" + Date.now() + "'><\/script>");
        document.write("<script src='" + localStorage.getItem("staticDomain") + "/admin/js/exam/papers.js?v=" + Date.now() + "'><\/script>");
    }else{
        document.write("<link rel='stylesheet' href='/static/component/laytp/css/laytp.css?v=" + Date.now() + "'>");
        document.write("<script src='/static/component/layui/layui.js?v=" + Date.now() + "'><\/script>");
        document.write("<script src='/static/component/laytp/layuiConfig.js?v=" + Date.now() + "'><\/script>");
    }
</script>

<script>

    layui.use(["laytp"], function () {
        const funController = {};
        //静态页面地址前缀
        window.htmlPrefix = facade.compatibleHtmlPath("/admin/exam/papers/");
        //后端接口地址前缀
        window.apiPrefix  = facade.compatibleApiRoute("/admin.exam.papers/");

        // 获取URL中的参数
        const urlParams = new URLSearchParams(window.location.search);
        var paper_id = urlParams.get('paper_id');
        var paper_status = urlParams.get('paper_status');


        //表格渲染
        funController.tableRender = function (where, page) {

            layui.table.render({
                elem: "#laytp-table"
                , limit: facade.getLimit('/admin/questions/')
                , id: "laytp-table"
                , url: facade.url("/admin.exam.papers/questionList",{paging:1, paper_id:paper_id})
                , toolbar: "#default-toolbar"
                , defaultToolbar: [{
                    title: '刷新',
                    layEvent: 'refresh',
                    icon: 'layui-icon-refresh',
                }, 'filter', 'print', 'exports']
                , where: where
                , method: "GET"
                , cellMinWidth: 120
                , skin: 'line'
                , loading: false
                , page: {
                    curr: page
                }
                , height: 'full-30'
                , parseData: function (res) { //res 即为原始返回的数据
                    layui.laytpTable.setLimit('/admin/questions/', res.data.per_page);
                    return facade.parseTableData(res, true);
                }
                , cols: [[
                    {field:'id',title:'ID',align:'center',width:80,fixed:'left'}
                    ,{field:'type',title:'题型',align:'center',templet:function(d){
                            return laytp.tableFormatter.status('type',d.type,{"value":["1","2","3","4","5"],"text":["单选题","多选题","判断题","简答题","填空题"]});
                        }}
                    ,{field:'title',title:'题干',align:'center'}
                    ,{field:'difficulty',title:'难度',align:'center',templet:function(d){
                            return laytp.tableFormatter.status('difficulty',d.difficulty,{"value":["1","2","3"],"text":["简单","中等","困难"]});
                        }}
                    ,{field:'category_name',title:'分类',align:'center'}
                    ,{field:'course_name',title:'课程名称',align:'center'}
                    ,{field:'user_name',title:'创建人',align:'center'}
                    ,{field:'operation',title:'操作',align:'center',toolbar:'#default-bar',width:150,fixed:'right'}
                ]]
            });



            //监听数据表格[操作列]按钮点击事件
            layui.table.on("tool(laytp-table)", function (obj) {

                    // //自定义按钮点击事件
                    switch(obj.event){
                        case "del":
                            facade.popupConfirm({ text: "确认删除么?", route: window.apiPrefix + "delPaperQuestions", data: { id: obj.data.id } });
                            break;

                        case "list":
                            let options = {};
                            let indexes = [];
                            options.width = '80%';
                            options.title = "试卷试题列表";
                            options.path = facade.compatibleHtmlPath(window.htmlPrefix) + "questions.html?id=" + obj.data.id;
                            indexes.push(facade.popupDiv(options));
                            break;

                        // //自定义按钮点击事件
                        // case "generating":
                        //     layui.layer.open({
                        //         type: 1,
                        //         title: '组卷',
                        //         area: ['80%', '80%'],
                        //         content: $('#layuiBox'),
                        //         success: function(layero, index) {
                        //
                        //         }
                        //     });
                        //     break;
                    }
            });

            //监听表头排序事件
            layui.table.on('sort(laytp-table)', function(obj){
                layui.table.reloadData('laytp-table', {
                    initSort: obj //记录初始排序，如果不设的话，将无法标记表头的排序状态。
                    , where: {
                        "order_param" : {
                            "field" : obj.field,
                            "type" : obj.type
                        }
                    }
                });
            });
        };



        funController.tableRender();

        window.funController = funController;
    });
</script>

</body>
</html>